package com.cloud.demo.models.sys.controller;

import com.cloud.demo.common.enums.ResultEnum;
import com.cloud.demo.common.web.domain.respomse.Result;
import com.cloud.demo.models.sys.domain.SysDept;
import com.cloud.demo.models.sys.qo.SysDeptQuery;
import com.cloud.demo.models.sys.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

/**
* 部门控制层
*/
@RestController
@RequestMapping("/sys/dept")
public class SysDeptController {

    @Autowired
    private SysDeptService departmentService;

    @PostMapping("/list")
    public Result list( @ModelAttribute("qo") SysDeptQuery qo){
        IPage<SysDept> page = departmentService.queryPage(qo);
        return Result.build(ResultEnum.SUCCESS,page);
    }

    @GetMapping("/get")
    public Result get(Long id){
        return Result.build(ResultEnum.SUCCESS,departmentService.getById(id));
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(SysDept department){
        departmentService.saveOrUpdate(department);
        return Result.build(ResultEnum.SUCCESS,null);
    }

    @DeleteMapping("/delete")
    public Object delete(Long id){
        departmentService.removeById(id);
        return Result.build(ResultEnum.SUCCESS,null);
    }
}
